package cn.tedu.mall.front.service.impl; 
 /*
 @Time: 2023/1/4 22:41
 @Author:GShuai
 @File:FrontProductServiceImpl.class
 @Software:IntelliJ IDEA
*/

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.front.service.IFrontProductService;
import cn.tedu.mall.pojo.product.vo.*;
import cn.tedu.mall.product.service.front.IForFrontAttributeService;
import cn.tedu.mall.product.service.front.IForFrontSkuService;
import cn.tedu.mall.product.service.front.IForFrontSpuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FrontProductServiceImpl implements IFrontProductService {

    @DubboReference
    private IForFrontSpuService dubboSpuService;
    // 声明消费Sku相关的业务逻辑
    @DubboReference
    private IForFrontSkuService dubboSkuService;
    // 声明消费商品参数选项(attribute) 的业务逻辑
    @DubboReference
    private IForFrontAttributeService dubboAttributeService;

    //根据分类id分页查询Spu列表i
    @Override
    public JsonPage<SpuListItemVO> listSpuByCategoryId(Long categoryId, Integer page, Integer pageSize) {

        // IForFrontSpuService实现类中完成的就是分页查询，所以我们直接调用即可
        JsonPage<SpuListItemVO> list = dubboSpuService.listSpuByCategoryId(categoryId,page,pageSize);
        // 返回
        return list;
    }

    //根据spuId查询Spu信息
    @Override
    public SpuStandardVO getFrontSpuById(Long id) {
        // dubbo调用spuService提供的方法即可
        SpuStandardVO spuStandardVO = dubboSpuService.getSpuById(id);
        // 返回查询到的对象spuStandardVO
        return spuStandardVO;
    }

    // 根据spuId查询Sku列表
    @Override
    public List<SkuStandardVO> getFrontSkusBySpuId(Long spuId) {
        // dubbo调用skuService提供的方法实现功能
        List<SkuStandardVO> list = dubboSkuService.getSkusBySpuId(spuId);
        return list;
    }

    // 根据SpuId查询spuDetail(Detail：详情)
    @Override
    public SpuDetailStandardVO getSpuDetail(Long spuId) {
        SpuDetailStandardVO spuDetailStandardVO = dubboSpuService.getSpuDetailById(spuId);
        return spuDetailStandardVO;
    }

    // 根据SpuId查询当前商品所有的参数的选项
    @Override
    public List<AttributeStandardVO> getSpuAttributesBySpuId(Long spuId) {
        // 这个查询运行的sql语句是一个5表联查
        // 在product模块中编写，需要额外注意
        List<AttributeStandardVO> list = dubboAttributeService.getSpuAttributesBySpuId(spuId);
        return list;
    }
}
